/**
 *
 * @author ace
 * @create 2017/7/11
 */
class GameOthers {

    //中断声音播放
    static soundPlay(type: SoundType, pos: number, ...args) {
        GameSound.play("sound_down");

        let gender: Gender = GSDataProxy.i.gData.getSexByPos(pos);
        let dir: Dir = PublicVal.i.getDir(pos);
        let sound: string = "";
        switch (type) {
            case SoundType.chi:
                sound = "chi_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 1);
                break;
            case SoundType.peng:
                sound = "cha_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 2);
                break;
            case SoundType.gang_ming:
                if (GameConfig.gameType == GameType.sichuan) {
                    sound = "sound_guafeng";
                    break;
                }

                sound = "gang_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 25);
                break;
            case SoundType.gang_an:
                if (GameConfig.gameType == GameType.sichuan) {
                    sound = "sound_xiayu";
                    break;
                }

                sound = "gang_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 24);
                break;
            case SoundType.gang_jian:
                sound = "gang_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 26);
                break;
            case SoundType.gang_feng:
                sound = "gang_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 23);
                break;
            case SoundType.buHua:
                sound = "buhua_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 29);
                break;
            case SoundType.ting:
                // sound = "ting_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 4);
                break;
            case SoundType.mingLou:
                // sound = "minglou_" + gender;
                GSController.i.gsView.playFuncEffect(dir, 347);
                break;
            case SoundType.hu:
                sound = (args[0] ? "zimo_" : "dianpao_") + gender;
                GSController.i.gsView.playFuncEffect(dir, 99);
                break;
            case SoundType.gangKai:
                sound = "zimo_" + gender;
                gameManager.i.dispatchEvent(EffectEvent.Gangshangkaihua, dir);
                break;
            case SoundType.yipaoduoxiang:
                sound = "dianpao_" + gender;
                gameManager.i.dispatchEvent(EffectEvent.Yipaoduoxiang, args[0]);
                break;
            case SoundType.hujiaozhuanyi:
                sound = "dianpao_" + gender;
                gameManager.i.dispatchEvent(EffectEvent.Hujiaozhuanyi, [dir, args[0]]);
                break;
        }

        if (sound != "") GameSound.play(sound);
    }

    //显示IP相同提示
    static showIP(arr: any[] = []): void {
        if (!GameConfig.switch_sameip) {
            return;
        }

        if (!arr || arr.length <= 1) return;

        let hasSame: boolean = false;
        for (let i = 0; i < arr.length; i++) {
            let pi = arr[i];
            if (!pi) continue;

            for (let j = 0; j < arr.length; j++) {
                let pj = arr[j];
                if (!pj) continue;
                if (+pi.uid == +pj.uid) continue;
                if (pi.ip.indexOf('.') == -1 || pj.ip.indexOf('.') == -1) continue;
                if (pi.ip == pj.ip) {
                    hasSame = true;
                    break;
                }
            }
            if (hasSame) break;
        }
        if (!hasSame) return;

        game.warning.play("注意：有玩家IP地址相同，请点击玩家头像查看");
    }

    //显示评价过低警告
    static showWarning(arr) {
        if (!arr || arr.length <= 1) return;

        let hasSame: boolean = false;
        for (let i = 0; i < arr.length; i++) {
            let pi = arr[i];
            if (!pi) continue;
            let zong: number = Number(pi.cai) + Number(pi.zan);
            let rate: number = zong == 0 ? 0 : ((pi.cai * 2) / zong);
            rate = rate > 1 ? 1 : rate;
            if (zong != 0 && rate > 0.5) {
                hasSame = true;
                break;
            }
            if (hasSame) break;
        }
        if (!hasSame) return;
        game.warning.play("警告：有玩家评价过低，请点击头像查看。");
    }

    //录音图片
    static _voiceImg: eui.Image;

    //显示录音
    static showVoice(): void {
        if (!this._voiceImg) this._voiceImg = new eui.Image();
        this._voiceImg.source = "game_icon_voice";
        this._voiceImg.horizontalCenter = 0;
        this._voiceImg.verticalCenter = 0;
        gameManager.layerManager.effectLayer.addChild(this._voiceImg);
    }

    //关闭录音
    static hideVoice(): void {
        // this.voiceStop = true;
        if (!this._voiceImg) return;
        if (gameManager.layerManager.effectLayer.contains(this._voiceImg)) {
            gameManager.layerManager.effectLayer.removeChild(this._voiceImg);
        }
    }
}